package log

import (
	"github.com/gin-gonic/gin"
	"higame/config"
	"higame/modules/store"
)

func fetchUsernameForAuth(ctx *gin.Context) (string, error) {
	claims, err := store.GetClaims(ctx)
	if err != nil {
		// 获取当前登录的用户失败
		return "", err
	}

	username := ctx.PostForm("username")
	if claims.Audience != config.AdminName {
		username = claims.Audience
	}
	return username, nil
}
